﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
//
using PerceptiveMCAPI;
using PerceptiveMCAPI.Types;
//

namespace PerceptiveMCAPI_Test
{
   public partial class show_campaigns : System.Web.UI.UserControl
   {
      // make a one liner & a detail in later release 

      public void Display( campaignsOutput output )
      {
         this.Visible = true;
         lblCount.Text = output.result.Count.ToString();
         lvwCampaigns.DataSource = output.result;
         lvwCampaigns.DataBind();

      }
      // -- show both this & MailChimp segment_text output

      protected string FormatSegmentOpts( object segment_opts )
      {
         campaignSegmentOptions so = (campaignSegmentOptions)segment_opts;
         if ( so.conditions.Count == 0 )
            return "** not segmented";

         StringBuilder sb = new StringBuilder();
         sb.AppendFormat( "Match: {0}, Conditions: ", so.match );
         foreach ( campaignSegmentCondition cond in so.conditions )
         {
            sb.AppendFormat( "[{0}.{1}.{2}.{3}], ", cond.field, cond.op, cond.value, cond.extra );
         }
         return sb.ToString( 0, sb.Length - 2 );

      }
   }
}